package com.youyi.yyviewsdklibrary.Dialog.impl;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.youyi.yyviewsdklibrary.Dialog.XPopup;
import com.youyi.yyviewsdklibrary.Dialog.core.BottomPopupView;
import com.youyi.yyviewsdklibrary.Dialog.interfaces.OnSelectListener;
import com.youyi.yyviewsdklibrary.Dialog.util.XPopupUtils;
import com.youyi.yyviewsdklibrary.Dialog.widget.CheckView;
import com.youyi.yyviewsdklibrary.Dialog.widget.VerticalRecyclerView;
import com.lkx.liandianqinew.R;
import com.zhy.adapter.recyclerview.CommonAdapter;
import com.zhy.adapter.recyclerview.MultiItemTypeAdapter;
import com.zhy.adapter.recyclerview.base.ViewHolder;
import java.util.Arrays;

public class BottomListPopupView extends BottomPopupView {
    protected int bindItemLayoutId;
    protected int bindLayoutId;
    int checkedPosition = -1;
    String[] data;
    int[] iconIds;
    RecyclerView recyclerView;
    private OnSelectListener selectListener;
    CharSequence title;
    TextView tv_cancel;
    TextView tv_title;
    View vv_divider;

    public BottomListPopupView(Context context, int i, int i2) {
        super(context);
        this.bindLayoutId = i;
        this.bindItemLayoutId = i2;
        addInnerContent();
    }

    /* access modifiers changed from: protected */
    @Override // com.youyi.yyviewsdklibrary.Dialog.core.BasePopupView, com.youyi.yyviewsdklibrary.Dialog.core.BottomPopupView
    public int getImplLayoutId() {
        int i = this.bindLayoutId;
        return i == 0 ? R.layout._xpopup_bottom_impl_list : i;
    }

    /* access modifiers changed from: protected */
    @Override // com.youyi.yyviewsdklibrary.Dialog.core.BasePopupView, com.youyi.yyviewsdklibrary.Dialog.core.BottomPopupView
    public void onCreate() {
        super.onCreate();
        RecyclerView recyclerView2 = (RecyclerView) findViewById(R.id.recyclerView);
        this.recyclerView = recyclerView2;
        if (this.bindLayoutId != 0) {
            recyclerView2.setLayoutManager(new LinearLayoutManager(getContext()));
        }
        this.tv_title = (TextView) findViewById(R.id.tv_title);
        this.tv_cancel = (TextView) findViewById(R.id.tv_cancel);
        this.vv_divider = findViewById(R.id.vv_divider);
        TextView textView = this.tv_cancel;
        if (textView != null) {
            textView.setOnClickListener(new OnClickListener() {
                /* class com.youyi.yyviewsdklibrary.Dialog.impl.BottomListPopupView.AnonymousClass1 */

                public void onClick(View view) {
                    BottomListPopupView.this.dismiss();
                }
            });
        }
        if (this.tv_title != null) {
            if (TextUtils.isEmpty(this.title)) {
                this.tv_title.setVisibility(View.GONE);
                if (findViewById(R.id.xpopup_divider) != null) {
                    findViewById(R.id.xpopup_divider).setVisibility(View.GONE);
                }
            } else {
                this.tv_title.setText(this.title);
            }
        }
        Context context = getContext();
        int i = this.bindItemLayoutId;
        if (i == 0) {
            i = R.layout._xpopup_adapter_text_match;
        }
        final CommonAdapter r0 = new CommonAdapter<String>(context, i, Arrays.asList(this.data)) {
            /* class com.youyi.yyviewsdklibrary.Dialog.impl.BottomListPopupView.AnonymousClass2 */

            /* access modifiers changed from: protected */
            public void convert(ViewHolder viewHolder, String str, int i) {
                viewHolder.setText(R.id.tv_text, str);
                ImageView imageView = (ImageView) viewHolder.getView(R.id.iv_image);
                int i2 = 0;
                if (BottomListPopupView.this.iconIds == null || BottomListPopupView.this.iconIds.length <= i) {
                    if (imageView != null) {
                        imageView.setVisibility(View.GONE);
                    }
                } else if (imageView != null) {
                    imageView.setVisibility(View.VISIBLE);
                    imageView.setImageResource(BottomListPopupView.this.iconIds[i]);
                }
                if (BottomListPopupView.this.checkedPosition != -1) {
                    if (viewHolder.getView(R.id.check_view) != null) {
                        View view = viewHolder.getView(R.id.check_view);
                        if (i != BottomListPopupView.this.checkedPosition) {
                            i2 = 8;
                        }
                        view.setVisibility(i2);
                        ((CheckView) viewHolder.getView(R.id.check_view)).setColor(XPopup.getPrimaryColor());
                    }
                    ((TextView) viewHolder.getView(R.id.tv_text)).setTextColor(i == BottomListPopupView.this.checkedPosition ? XPopup.getPrimaryColor() : BottomListPopupView.this.getResources().getColor(R.color._xpopup_title_color));
                } else {
                    if (viewHolder.getView(R.id.check_view) != null) {
                        viewHolder.getView(R.id.check_view).setVisibility(View.GONE);
                    }
                    ((TextView) viewHolder.getView(R.id.tv_text)).setGravity(17);
                }
                if (BottomListPopupView.this.bindItemLayoutId != 0) {
                    return;
                }
                if (BottomListPopupView.this.popupInfo.isDarkTheme) {
                    ((TextView) viewHolder.getView(R.id.tv_text)).setTextColor(BottomListPopupView.this.getResources().getColor(R.color._xpopup_white_color));
                } else {
                    ((TextView) viewHolder.getView(R.id.tv_text)).setTextColor(BottomListPopupView.this.getResources().getColor(R.color._xpopup_dark_color));
                }
            }
        };
        r0.setOnItemClickListener(new MultiItemTypeAdapter.OnItemClickListener() {
            /* class com.youyi.yyviewsdklibrary.Dialog.impl.BottomListPopupView.AnonymousClass3 */

            @Override // com.zhy.adapter.recyclerview.MultiItemTypeAdapter.OnItemClickListener
            public boolean onItemLongClick(View view, RecyclerView.ViewHolder viewHolder, int i) {
                return false;
            }

            @Override // com.zhy.adapter.recyclerview.MultiItemTypeAdapter.OnItemClickListener
            public void onItemClick(View view, RecyclerView.ViewHolder viewHolder, int i) {
                if (BottomListPopupView.this.selectListener != null) {
                    BottomListPopupView.this.selectListener.onSelect(i, (String) r0.getDatas().get(i));
                }
                if (BottomListPopupView.this.checkedPosition != -1) {
                    BottomListPopupView.this.checkedPosition = i;
                    r0.notifyDataSetChanged();
                }
                BottomListPopupView.this.postDelayed(new Runnable() {
                    /* class com.youyi.yyviewsdklibrary.Dialog.impl.BottomListPopupView.AnonymousClass3.AnonymousClass1 */

                    public void run() {
                        if (BottomListPopupView.this.popupInfo.autoDismiss.booleanValue()) {
                            BottomListPopupView.this.dismiss();
                        }
                    }
                }, 100);
            }
        });
        this.recyclerView.setAdapter(r0);
        applyTheme();
    }

    public BottomListPopupView setStringData(CharSequence charSequence, String[] strArr, int[] iArr) {
        this.title = charSequence;
        this.data = strArr;
        this.iconIds = iArr;
        return this;
    }

    public BottomListPopupView setOnSelectListener(OnSelectListener onSelectListener) {
        this.selectListener = onSelectListener;
        return this;
    }

    public BottomListPopupView setCheckedPosition(int i) {
        this.checkedPosition = i;
        return this;
    }

    /* access modifiers changed from: protected */
    public void applyTheme() {
        if (this.bindLayoutId != 0) {
            return;
        }
        if (this.popupInfo.isDarkTheme) {
            applyDarkTheme();
        } else {
            applyLightTheme();
        }
    }

    /* access modifiers changed from: protected */
    @Override // com.youyi.yyviewsdklibrary.Dialog.core.BasePopupView
    public void applyDarkTheme() {
        super.applyDarkTheme();
        ((VerticalRecyclerView) this.recyclerView).setupDivider(true);
        this.tv_title.setTextColor(getResources().getColor(R.color._xpopup_white_color));
        TextView textView = this.tv_cancel;
        if (textView != null) {
            textView.setTextColor(getResources().getColor(R.color._xpopup_white_color));
        }
        findViewById(R.id.xpopup_divider).setBackgroundColor(getResources().getColor(R.color._xpopup_list_dark_divider));
        View view = this.vv_divider;
        if (view != null) {
            view.setBackgroundColor(Color.parseColor("#1B1B1B"));
        }
        getPopupImplView().setBackground(XPopupUtils.createDrawable(getResources().getColor(R.color._xpopup_dark_color), this.popupInfo.borderRadius, this.popupInfo.borderRadius, 0.0f, 0.0f));
    }

    /* access modifiers changed from: protected */
    @Override // com.youyi.yyviewsdklibrary.Dialog.core.BasePopupView
    public void applyLightTheme() {
        super.applyLightTheme();
        ((VerticalRecyclerView) this.recyclerView).setupDivider(false);
        this.tv_title.setTextColor(getResources().getColor(R.color._xpopup_dark_color));
        TextView textView = this.tv_cancel;
        if (textView != null) {
            textView.setTextColor(getResources().getColor(R.color._xpopup_dark_color));
        }
        findViewById(R.id.xpopup_divider).setBackgroundColor(getResources().getColor(R.color._xpopup_list_divider));
        View view = this.vv_divider;
        if (view != null) {
            view.setBackgroundColor(getResources().getColor(R.color._xpopup_white_color));
        }
        getPopupImplView().setBackground(XPopupUtils.createDrawable(getResources().getColor(R.color._xpopup_light_color), this.popupInfo.borderRadius, this.popupInfo.borderRadius, 0.0f, 0.0f));
    }
}
